From 474282e508429c6e527a419a71bc7a3f838d74a7 Mon Sep 17 00:00:00 2001 From: Chad Horohoe Date: Fri, 29 Apr 2011 22:08:58 +0000 Subject: [PATCH] Add cdb.php for inspecting cdb cache files. Format is stolen from mcc.php --- maintenance/cdb.php | 119 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 maintenance/cdb.php diff --git a/maintenance/cdb.php b/maintenance/cdb.php new file mode 100644 index 0000000000..270f7a60f3 --- /dev/null +++ b/maintenance/cdb.php @@ -0,0 +1,119 @@ + 'load a cdb file for reading', + 'get' => 'get a value for a key', + 'exit' => 'exit cdb', + 'quit' => 'exit cdb', + 'help' => 'help about a command', + ); + if ( !$command ) { + $command = 'fullhelp'; + } + if ( $command === 'fullhelp' ) { + $max_cmd_len = max( array_map( 'strlen', array_keys( $commandList ) ) ); + foreach ( $commandList as $cmd => $desc ) { + printf( "%-{$max_cmd_len}s: %s\n", $cmd, $desc ); + } + } elseif ( isset( $commandList[$command] ) ) { + print "$command: $commandList[$command]\n"; + } else { + print "$command: command does not exist or no help for it\n"; + } +} + +do { + $bad = false; + $showhelp = false; + $quit = false; + static $fileHandle; + + $line = Maintenance::readconsole(); + if ( $line === false ) exit; + + $args = explode( ' ', $line ); + $command = array_shift( $args ); + + // process command + switch ( $command ) { + case 'help': + // show an help message + cdbShowHelp( array_shift( $args ) ); + break; + case 'load': + if( !isset( $args[0] ) ) { + print "Need a filename there buddy\n"; + break; + } + $file = $args[0]; + print "Loading cdb file $file..."; + $fileHandle = CdbReader::open( $file ); + if( !$fileHandle ) { + print "not a cdb file or unable to read it\n"; + } else { + print "ok\n"; + } + break; + case 'get': + if( !$fileHandle ) { + print "Need to load a cdb file first\n"; + break; + } + if( !isset( $args[0] ) ) { + print "Need to specify a key, Luke\n"; + break; + } + $res = $fileHandle->get( $args[0] ); + if ( $res === false ) { + print "No such key/value pair\n"; + } elseif ( is_string( $res ) ) { + print "$res\n"; + } else { + var_dump( $res ); + } + break; + case 'quit': + case 'exit': + $quit = true; + break; + + default: + $bad = true; + } // switch() end + + if ( $bad ) { + if ( $command ) { + print "Bad command\n"; + } + } else { + if ( function_exists( 'readline_add_history' ) ) { + readline_add_history( $line ); + } + } +} while ( !$quit ); -- 2.20.1